<template>
  <div class="menu-item" :class="{ active: active }" @click="handleClick" ref="menuItem">
    <div class="content">
      <div class="svg">
        <component :is="svg" :active="active" :transiton="0.3" />
        <slot></slot>
      </div>
      <span class="text">{{ text }}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'x-menu-item',
    props: ['svg', 'text', 'label'],
    computed: {
      active: {
        get() {
          return this.label === this.$parent.value
        },
        set(val) {
          if (val) this.$parent.changeActiveLabel(this.label)
        },
      },
    },
    methods: {
      handleClick() {
        this.active = true
      },
    },
  }
</script>

<style lang="scss" scoped>
  .menu-item {
    width: 200px;
    height: 44px;
    margin-top: 4px;
    transition: all 0.3s ease;
    // background-color: pink;

    &:hover .content {
      background: #f4f9fd;
    }

    &.active {
      &:hover .content {
        background: transparent !important;
      }
      background: transparent !important;
      .text {
        color: rgba(63, 140, 255, 1);
      }
    }
  }

  .content {
    display: flex;
    align-items: center;
    width: 172px;
    height: 44px;
    margin-left: 15px;
    border-radius: 10px;
    background: transparent;
    cursor: pointer;

    .svg {
      width: 20px;
      height: 20px;
      margin-left: 11px;
    }
    .text {
      font-size: 16px;
      font-weight: 500;
      letter-spacing: 0px;
      line-height: 24px;
      color: rgba(63, 140, 255, 1);
      text-align: left;
      vertical-align: middle;
      margin-left: 16px;
      color: rgba(113, 128, 150, 1);
    }
  }
</style>
